import { defHttp } from '@/utils/http';

enum Api {
  getList = '/v1/system/user',
  save = '/v1/system/user',
  del = '/v1/system/user',
  upStatus = '/v1/system/user/state',
  getAll = '/v1/system/user/all',
  UpdateInfo = '/v1/system/user',
  resetPassword = '/v1/system/user/reset_password',
  changePassword = '/v1/system/user/password',
}

//获取数据
export function getList(params: object) {
  return defHttp.get(
    { url: Api.getList, params: params },
    { errorMessageMode: 'none' }
  );
}

//新增
export function add(params: object) {
  return defHttp.post(
    { url: Api.save, params: params },
    { errorMessageMode: 'message' }
  );
}

//修改
export function update(params: object) {
  return defHttp.put(
    { url: Api.UpdateInfo, params: params },
    { errorMessageMode: 'message' }
  );
}

//删除数据
export function del(params: object) {
  return defHttp.delete(
    { url: Api.del, params: params },
    { errorMessageMode: 'message' }
  );
}

//更新状态
export function upStatus(params: object) {
  return defHttp.put(
    { url: Api.upStatus, params: params },
    { errorMessageMode: 'message' }
  );
}

//重置密码
export function resetPassword(params: object) {
  return defHttp.put(
    { url: Api.resetPassword, params: params },
    { errorMessageMode: 'message' }
  );
}

//获取全部数据
export function getAllUser(params: object) {
  return defHttp.post(
    { url: Api.getAll, params: params },
    { errorMessageMode: 'message' }
  );
}

//修改密码
export interface ChangeData {
  user_password: string;
  new_password: string;
}

export function changePassword(params: ChangeData) {
  params = Object.assign({}, params, {
    user_password: md5(params.user_password),
  }); //加密推送
  params = Object.assign({}, params, {
    new_password: md5(params.new_password),
  }); //加密推送
  return defHttp.put(
    { url: Api.changePassword, params: params },
    { errorMessageMode: 'message' }
  );
}
